package net.interneteidee.controller;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider;

import net.interneteidee.entity.Cliente;
import net.interneteidee.entity.Famiglia;
import net.interneteidee.entity.Fattura;
import net.interneteidee.entity.ProdottoEsterno;
import net.interneteidee.servizi.ClienteService;
import net.interneteidee.servizi.ProdottoCategoriaFamigliaService;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;


@ManagedBean
@SessionScoped
public class ClienteController {


	private List allClients;
	private int currentClientId = 1;

	private int page = 1;
	private int contatore = 1;

	@Inject
	ClienteService clienteService;
	
	@Inject
	ProdottoCategoriaFamigliaService prodottoCategoriaFamigliaService;

	public ClienteController() {

	}

	@PostConstruct
	public void init() {
		System.out.println("Init Cliente Controller");
	}
	
	@PreDestroy 
	public void delete(){
		System.out.println("Delete Cliente Controller");
	}

	public void addClient(Cliente clienteDaSalvare) {
		clienteService.addClient(clienteDaSalvare);
		refreshListOfClient();
		//clienteDaAggiungere = new Cliente();
	}

	public void removeClient(Cliente clienteDaEliminare) {
		clienteService.removeClient(clienteDaEliminare);
		refreshListOfClient();

	}

	

	public void refreshListOfClient() {
		allClients.clear();
		allClients = clienteService.findAllClients();
		Collections.sort(allClients);
	}

	public void findAllClient() {
		allClients = clienteService.findAllClients();
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public List<Cliente> getAllClients() {
		return allClients;
	}

	public void setAllClients(List<Cliente> allClients) {
		this.allClients = allClients;
	}

	public int getCurrentClientId() {
		return currentClientId;
	}

	public void setCurrentClientId(int currentClientId) {
		this.currentClientId = currentClientId;
	}

	public int getContatore() {
		return contatore;
	}

	public void setContatore(int contatore) {
		this.contatore = contatore;
	}

	public void incrementaContatore() {
		contatore++;
	}
	
}
